#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../inc/student.h"
#include "../inc/admin.h"
#include "../inc/general.h"

// 返回主菜单
void return_Main()
{
    while (1)
    {
        char c;
        print_Lines();
        printf("输入 Q 返回上一级:");
        while (1)
        {
            scanf(" %c", &c);
            while (getchar() != '\n')
                ;
            if (c == 'q' || c == 'Q')
            {
                clearScreen();
                return;
            }
            else
            {
                printf("输入错误，请重新输入:");
            }
        }
    }
}

// 退出功能页面
int return_function()
{
    while (1)
    {
        print_Lines();
        char c;
        printf("是否重新执行?(Y/N)");
        scanf(" %c", &c);
        while (getchar() != '\n')
            ;
        if (c == 'Y' || c == 'y')
        {
            clearScreen();
            return 1;
        }
        else if (c == 'N' || c == 'n')
        {
            clearScreen();
            return -1;
        }
        else
        {
            printf("输入错误,请重新输入!\n");
        }
    }
}

// 菜单输入
int *scanf_menu(int *menu)
{
    while (1)
    {
        int result = scanf("%d", menu);
        if (result != 1 || *menu < 0 || *menu > 9)
        {
            printf("输入异常!重新输入:");
            while (getchar() != '\n')
            {
                continue; // 丢弃所有剩余字符，包括回车
            }
            continue;
        }
        else
        {
            break;
        }
    }
    return menu;
}

// 清屏函数
void clearScreen()
{
#ifdef _WIN32
    system("cls");
#else
    system("clear");
#endif
}

// 打印分隔线
void print_Lines()
{
    printf("----------------------------------------------\n");
}

// 打印分隔线*
void print_Lines2()
{
    // printf("**********************************************\n");
    printf("==============================================\n");
}